<template>
  <div class="dashboard-container">
    <div v-for="(line, index) in groupedLines" :key="index" class="box-line">
      <div class="box">
        <th>{{ line.title }}</th>
        <div class="line"></div>
        <td v-for="(item, itemIndex) in line.items" :key="itemIndex">
          <router-link :to="item.path">{{ item.title }}</router-link>
        </td>
      </div>
    </div>
  </div>
</template>

<script>
import { getRouter } from "@/api/system/user";

export default {
  name: "Dashboard",
  data() {
    return {
      groupedLines: [],
    };
  },
  created() {
    this.getRouterData();
  },
  methods: {
    getRouterData() {
      getRouter().then((res) => {
        if (res.code === 200) {
          this.processRouterData(res.data);
        }
      });
    },
    processRouterData(data) {
      const titleMap = {};

      data.forEach((group) => {
        const title = group.meta.title;
        const items = group.children.map((child) => ({
          title: child.meta.title,
          path: child.path,
        }));

        if (!titleMap[title]) {
          titleMap[title] = { title, items };
        } else {
          titleMap[title].items.push(...items);
        }
      });

      this.groupedLines = Object.values(titleMap);
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard-container {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-left: 210px;
}

.box {
  display: flex;
  justify-content: center;
  align-items: baseline;
  flex-flow: column;
  margin: 30px 0px 40px 40px;
  th {
    font-size: 20pt;
    font-weight: normal;
    color: #333;
  }
  td {
    margin: 10px 0 10px 0;
    color: #666;
    font-size: 18px;
  }
}

.line {
  height: 1px;
  color: #9999;
  background: #9999;
  width: 216px;
  margin: 10px 0px 10px 0;
  margin-left: 20px;
}
</style>
